<?php namespace App\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * Class VerifierWorksAssign
 *
 * @package App\Models
 * @property int $id
 * @property string $created_at
 * @property string $updated_at
 * @property int $user_id
 * @property int $works_type_id
 * @property int $proposition_company_id
 * @property int $status
 * @property-read \App\Models\Verifier $user
 * @property-read \App\Models\WorksType $worksType
 * @property-read \App\Models\PropositionCompany $propositionCompany
 * @method static \Illuminate\Database\Query\Builder|\App\Models\VerifierWorksAssign whereId($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Models\VerifierWorksAssign whereCreatedAt($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Models\VerifierWorksAssign whereUpdatedAt($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Models\VerifierWorksAssign whereUserId($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Models\VerifierWorksAssign whereWorksTypeId($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Models\VerifierWorksAssign wherePropositionCompanyId($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Models\VerifierWorksAssign whereStatus($value)
 * @mixin \Eloquent
 */
class VerifierWorksAssign extends Model
{
    public function user()
    {
        return $this->belongsTo(Verifier::class, 'user_id');
    }

    public function worksType()
    {
        return $this->belongsTo(WorksType::class, 'works_type_id');
    }

    public function propositionCompany()
    {
        return $this->belongsTo(PropositionCompany::class, 'proposition_company_id');
    }

    public function worksCount()
    {
        return Works::where('is_hidden', 0)->where('works_type_id', $this->works_type_id)
            ->where('proposition_company_id', $this->proposition_company_id)
            ->count();
    }
}